package HashTable;

import java.util.HashMap;
import java.util.concurrent.CountDownLatch;

/**
 * @author wang'ji'cheng
 * @date 2025/7/28
 */
public class HashMapTest {
    public static void main(String[] args) throws InterruptedException {

        HashMap<Integer, Integer> hm = new HashMap<>();
        //计数器，用于确定线程能够正确执行
        CountDownLatch countDownLatch = new CountDownLatch(2);
        new Thread(()->{
            for (int i = 1; i <26; i++) {
                hm.put(i,i);
            }
            countDownLatch.countDown();
        }).start();
        new Thread(()->{
            for (int i = 26; i <51; i++) {
                hm.put(i,i);
            }
            countDownLatch.countDown();
        }).start();

        countDownLatch.await();
        System.out.println(hm);
    }
}
